# -*- coding: utf-8 -*-

from multiprocessing import Process

class file_socket_gateway(Process):
	def __init__(self,**kwargs):
		super(read_socket_write_file, self).__init__()
		self.working_parameters=kwargs
		self.start()
		pass
	pass

class read_file_write_socket(file_socket_gateway):
	'''读文件写socket'''
	
	def run(self):
		buffer_size=self.working_parameters['buffer_size']
		ip_port=self.working_parameters['address']
		fd=self.working_parameters['fd']
		
		with open(self.working_parameters['buffer_filename'], mode="wb+") as buffer_file_fd:
			while 1:
				data=fd.recv(buffer_size)
				buffer_file_fd.write(data)
				buffer_file_fd.flush()
				pass
			pass
		
		pass
	pass

class read_socket_write_file(file_socket_gateway):
	'''读socket写文件'''
	
	def run(self):
		'''从socket连接读取内容然后写入缓存文件'''
		buffer_size=self.working_parameters['buffer_size']
		ip_port=self.working_parameters['address']
		fd=self.working_parameters['fd']
		with open(self.working_parameters['buffer_filename'],mode="wb+") as buffer_file_fd:
			while 1:
				data=fd.recv(buffer_size)
				buffer_file_fd.write(data)
				buffer_file_fd.flush()
				pass
			pass
		
	pass

